﻿using Net5ApiANdWpfClient.Lib.Model.SystemAdmin;
using Net5ApiANdWpfClient.Lib.Service;
using Net5ApiANdWpfClient.WpfClient.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WPF.MDI;

namespace Net5ApiANdWpfClient.WpfClient.SystemManager
{
    /// <summary>
    /// AdminUserAdd.xaml 的交互逻辑
    /// </summary>
    public partial class AdminUserAdd : BaseUserControl
    {
        AdminUser adminUser = new AdminUser();
        public AdminUserAdd()
        {
            InitializeComponent();
           
            this.DataContext = adminUser;
        }
     


        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(adminUser.user_name))
            {
                MessageBox.Show("用户名不能为空!");
                return;
            }

            if (string.IsNullOrEmpty(adminUser.user_full_name))
            {
                MessageBox.Show("姓名不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(adminUser.pass_word))
            {
                MessageBox.Show("密码不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(adminUser.v_pass_word))
            {
                MessageBox.Show("验证密码不能为空!");
                return;
            }
            if (adminUser.pass_word != adminUser.v_pass_word)
            {
                MessageBox.Show("密码与验证密码不一致!");
                return;
            }
            adminUser.creator_date = DateTime.Now;
            adminUser.creator_name = LoginUser.userData.user_name;
            AdminUserService service = new AdminUserService();
            string mess = "";
            bool result = service.AdminUserAdd(adminUser,out mess);
            if (result)
            {
                MessageBox.Show($"添加成功,具体原因是:{mess}!");

                MainWindow main = WindowsManager.GetWindowInCurrentWindows<MainWindow>();
                if (main != null)
                {
                    AdminUserManager adminUser = MdiManager.GetControlInMdiContainer<AdminUserManager>(main.MainMdiWindow);
                     adminUser?.Search();
                    MdiChild child = MdiManager.GetMdiChild(main.MainMdiWindow, this);
                    child?.Close();
                }
              
            }
            else {
                MessageBox.Show($"添加失败,具体原因是:{mess}!");
            }

        }
    }









}
